﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Obsidian.Components
{
    public struct Frame
    {
        public Frame(Texture2D texture)
        {
            Texture = texture;
            SourceRect = new Rectangle(0, 0, texture.Width, texture.Height);
            CenterPoint = new Vector2((float)texture.Width / 2.0f, (float)texture.Height / 2.0f);
            FlipMode = SpriteEffects.None;
        }

        public Frame(Texture2D texture, Vector2 centerPoint, SpriteEffects flipMode)
        {
            Texture = texture;
            SourceRect = new Rectangle(0, 0, texture.Width, texture.Height);
            CenterPoint = centerPoint;
            FlipMode = flipMode;
            FixCenter();
        }

        public Frame(Texture2D texture, Rectangle sourceRect, Vector2 centerPoint, SpriteEffects flipMode)
        {
            Texture = texture;
            SourceRect = sourceRect;
            CenterPoint = centerPoint;
            FlipMode = flipMode;
            FixCenter();
        }

        private void FixCenter()
        {
            if ((FlipMode & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically)
            {
                CenterPoint = new Vector2(CenterPoint.X, SourceRect.Height - CenterPoint.Y);
            }

            if ((FlipMode & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally)
            {
                CenterPoint = new Vector2(SourceRect.Width - CenterPoint.X, CenterPoint.Y);
            }
        }

        public Texture2D Texture;
        public Rectangle SourceRect;
        public Vector2 CenterPoint;
        public SpriteEffects FlipMode;
    }
}
